package com.tunan.config;

import java.security.spec.PSSParameterSpec;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

@Configuration
@EnableAutoConfiguration
@ConfigurationProperties(locations = "classpath:redis.properties", prefix = "redis")
public class RedisConfig {
	private int port;
	private String server;
	private int timeout;
	private String password;
	private String serverList;

	@Bean
	public JedisPoolConfig jedisPoolConfig() {
		JedisPoolConfig jpc = new JedisPoolConfig();
		jpc.setMaxTotal(50);
		return jpc;
	}

	@Bean(name = "jedisPool")
	public JedisPool jedisPool() {
		return new JedisPool(jedisPoolConfig(), server, port, timeout, password);
	}

	/**
	 * 
	 * @return ShardedJedisPool
	 * @Description 预留分片式redis使用
	 * @date 2016年3月31日
	 * @author kinda
	 */
	// @Bean
	// public ShardedJedisPool shardedJedisPool() {
	// List<JedisShardInfo> sList = Stream.of(serverList.split(",")).map(m ->
	// new JedisShardInfo(m,port)).collect(Collectors.toList());
	// return new ShardedJedisPool(jedisPoolConfig(), sList);
	// }

	public String getServer() {
		return server;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public void setServer(String server) {
		this.server = server;
	}

	public String getServerList() {
		return serverList;
	}

	public void setServerList(String serverList) {
		this.serverList = serverList;
	}

	public int getTimeout() {
		return timeout;
	}

	public void setTimeout(int timeout) {
		this.timeout = timeout;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
